package assignment6;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;

/**
 * Class for GUI Panel interface
 * 
 * @author Terry Wasserleben CS204-21370 Prof. Jeannette Myers Due: 11/02/2011
 */
@SuppressWarnings("serial")
public class MorseCodePanel extends JPanel {
	/**
	 * JTextPane contains the final translation to English text
	 */
	private JTextPane engTrans;
	
	/**
	 * JTextPane contains the Morse code string that will be translated
	 */
	private JTextPane morseCode;
	
	/**
	 * creates relationship to MorseCodeConverter.java
	 */
	public MorseCodeConverter mcc = new MorseCodeConverter();
	
	/**
	 * Constructor for GUI Panel
	 */
	public MorseCodePanel() {
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] { 0, 0, 0, 0, 0, 0 };
		gridBagLayout.rowHeights = new int[] { 40, 100, 40, 100, 40, 0 };
		gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 1.0, 1.0, 0.0,
				Double.MIN_VALUE };
		gridBagLayout.rowWeights = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0,
				Double.MIN_VALUE };
		setLayout(gridBagLayout);
		
		JLabel mcLabel = new JLabel(
				"Morse Code (\" \" (space) is separator for letters \"/\" (slash) for words)");
		GridBagConstraints gbc_mcLabel = new GridBagConstraints();
		gbc_mcLabel.gridwidth = 3;
		gbc_mcLabel.insets = new Insets(0, 0, 5, 5);
		gbc_mcLabel.gridx = 1;
		gbc_mcLabel.gridy = 0;
		add(mcLabel, gbc_mcLabel);
		
		morseCode = new JTextPane();
		morseCode.setToolTipText("Enter Morse Code characters \".\" and \"-\"");
		GridBagConstraints gbc_morseCode = new GridBagConstraints();
		gbc_morseCode.gridwidth = 3;
		gbc_morseCode.insets = new Insets(0, 0, 5, 5);
		gbc_morseCode.fill = GridBagConstraints.BOTH;
		gbc_morseCode.gridx = 1;
		gbc_morseCode.gridy = 1;
		add(morseCode, gbc_morseCode);
		
		JLabel engLabel = new JLabel(
				"English Translation     (if character unknown: [IDK] appears)");
		GridBagConstraints gbc_engLabel = new GridBagConstraints();
		gbc_engLabel.gridwidth = 3;
		gbc_engLabel.insets = new Insets(0, 0, 5, 5);
		gbc_engLabel.gridx = 1;
		gbc_engLabel.gridy = 2;
		add(engLabel, gbc_engLabel);
		
		engTrans = new JTextPane();
		engTrans
				.setToolTipText("Non-Editable: English Translation appears here");
		engTrans.setEditable(false);
		GridBagConstraints gbc_engTrans = new GridBagConstraints();
		gbc_engTrans.gridwidth = 3;
		gbc_engTrans.insets = new Insets(0, 0, 5, 5);
		gbc_engTrans.fill = GridBagConstraints.BOTH;
		gbc_engTrans.gridx = 1;
		gbc_engTrans.gridy = 3;
		add(engTrans, gbc_engTrans);
		
		JButton btnConvertFile = new JButton("Convert File");
		btnConvertFile
				.setToolTipText("Select File in morse code characters for translation");
		btnConvertFile.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				engTrans.setText(mcc.convertToEnglish(mcc.chooserDialog()));
			}
		});
		GridBagConstraints gbc_btnConvertFile = new GridBagConstraints();
		gbc_btnConvertFile.insets = new Insets(0, 0, 0, 5);
		gbc_btnConvertFile.gridx = 1;
		gbc_btnConvertFile.gridy = 4;
		add(btnConvertFile, gbc_btnConvertFile);
		
		JButton btnConvertString = new JButton("Convert String");
		btnConvertString
				.setToolTipText("Enter the Morse Code string into the appropriate space provided");
		btnConvertString.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				engTrans.setText(mcc.convertToEnglish(morseCode.getText()));
			}
		});
		GridBagConstraints gbc_btnConvertString = new GridBagConstraints();
		gbc_btnConvertString.insets = new Insets(0, 0, 0, 5);
		gbc_btnConvertString.gridx = 2;
		gbc_btnConvertString.gridy = 4;
		add(btnConvertString, gbc_btnConvertString);
		
		JButton btnExit = new JButton("Exit");
		btnExit.setToolTipText("Press to Exit");
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		GridBagConstraints gbc_btnExit = new GridBagConstraints();
		gbc_btnExit.insets = new Insets(0, 0, 0, 5);
		gbc_btnExit.gridx = 3;
		gbc_btnExit.gridy = 4;
		add(btnExit, gbc_btnExit);
		
	}
}
